package com.pengtu.service.asset;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.dao.Page;
import com.pengtu.dao.QueryFilter;
import com.pengtu.dao.asset.equipment.EquipCheckDao;
import com.pengtu.dao.asset.equipment.EquipInformationDao;
import com.pengtu.dao.asset.equipment.MaintenanceDao;
import com.pengtu.entity.asset.equipment.EquipCheck;
import com.pengtu.entity.asset.equipment.EquipInformation;
import com.pengtu.entity.asset.equipment.EquipMaintenance;

@Component
@Transactional
public class EquipmentManager {

	private Logger logger = Logger.getLogger(EquipmentManager.class);

	/* 操作equipment.information */
	private EquipInformationDao informationDao;
	private EquipCheckDao testDao;
	private MaintenanceDao maintenanceDao;

	@Autowired
	public void setInformationDao(EquipInformationDao informationDao) {
		this.informationDao = informationDao;
	}
	

	@Autowired
	public void setTestDao(EquipCheckDao testDao) {
		this.testDao = testDao;
	}
	@Autowired
	public void setMaintenanceDao(MaintenanceDao maintenanceDao) {
		this.maintenanceDao = maintenanceDao;
	}
	/**
	 * 执行增加或修改操作
	 */
	public void saveOrUpdateInformation(EquipInformation information) {
		informationDao.save(information);
	}
	/**
	 * 执行删除操作
	 */
	public void deleteInformatin(String informationId){
		informationDao.delete(informationId);
	}
	
	/**
	 * 
	 * @param propertyName
	 * @param value
	 * @return
	 * 按照属性名查找单位信息
	 */
	public EquipInformation getProperty(String propertyName,String value){
		if(propertyName.equalsIgnoreCase("id")){
			return informationDao.get(value);
		}
		return informationDao.findUniqueBy(propertyName, value);
	}
	
	/**
	 * 分页显示
	 */
	@Transactional(readOnly=true)
	public Page<EquipInformation> findFuzzyPageInformation(final Page<EquipInformation> page,final QueryFilter filters){
		
		return informationDao.findPage(page, filters);
	}
	
	/**
	 * 根据属性名查找对象
	 * @param equipNo
	 * @return
	 */
	public EquipInformation findEquipByProperty(String equipNo) {
		// TODO Auto-generated method stub
		return informationDao.findUniqueBy("equipmentNo", equipNo);
	}
	/* 操作Check对象          */
	
	/**
	 * 执行增加或修改操作
	 */
	public void saveOrUpdateTest(EquipCheck test){
		if(StringUtils.isEmpty(test.getId())){
			testDao.save(test);
			logger.warn("save Test !****");
		}else{
			testDao.update(test);
			logger.warn("update Test!&&&&&");
		}
	}
	/**
	 * 执行删除操作
	 * @param testId
	 */
	public void deleteTest(String testId){
		testDao.delete(testId);
	}
	/**
	 * 根据属性名获取单位信息
	 * @param propertyName
	 * @param value
	 * @return
	 */
	@Transactional(readOnly=true)
	public EquipCheck findPropertyTest(String propertyName,String value){
		if(propertyName.equalsIgnoreCase("id")){
			return testDao.get(value);
		}
		return testDao.findUniqueBy(propertyName, value);
	}
	/**
	 * 获取全部数据信息
	 * @return
	 */
	@Transactional(readOnly=true)
	public List<EquipCheck> findAllTest(){
		return testDao.find();
	}
	/**
	 * 分页查询
	 * @param page
	 * @return
	 */
	@Transactional(readOnly=true)
	public Page<EquipCheck> findFuzzyEquipCheck(final Page<EquipCheck> page){
		return testDao.findPage(page);
	}
	/**
	 * 根据外键查找集合对象
	 * @param propertyName
	 * @param value
	 * @return
	 */
	public List<EquipCheck> findEquipCheckList(String propertyName,String value){
		return testDao.findBy(propertyName, value);
	}
	
	/*操作Maintenance 对象  */
	
	/**
	 * 执行增加或修改操作
	 */
	public void saveOrUpdateMaintenance(EquipMaintenance maintenance){
		if(StringUtils.isEmpty(maintenance.getId())){
			maintenanceDao.save(maintenance);
			logger.warn("save Maintenance !****");
		}else{
			maintenanceDao.update(maintenance);
			logger.warn("update Maintenance!&&&&&");
		}
	}
	/**
	 * 执行删除操作
	 * @param maintenanceId
	 */
	public void deleteMaintenance(String maintenanceId){
		maintenanceDao.delete(maintenanceId);
	}
	/**
	 * 根据属性名获取单位信息
	 * @param propertyName
	 * @param value
	 * @return
	 */
	@Transactional(readOnly=true)
	public EquipMaintenance findPropertyMaintenance(String propertyName,String value){
		if(propertyName.equalsIgnoreCase("id")){
			return maintenanceDao.get(value);
		}
		return maintenanceDao.findUniqueBy(propertyName, value);
	}
	/**
	 * 获取全部数据信息
	 * @return
	 */
	@Transactional(readOnly=true)
	public List<EquipMaintenance> findAllMaintenance(){
		return maintenanceDao.find();
	}
	
	/**
	 * 分页查询
	 * @param page
	 * @return
	 */
	@Transactional(readOnly=true)
	public Page<EquipMaintenance> findFuzzyEquipMaintenance(final Page<EquipMaintenance> page){
		return maintenanceDao.findPage(page);
	}

	/**
	 * 根据外键查找集合对象
	 * @param propertyName
	 * @param value
	 * @return
	 */
	public List<EquipMaintenance> findEquipMaintenanceList(String propertyName,String value){
		return maintenanceDao.findBy(propertyName, value);
	}

	
	
	
}
